#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<stdlib.h>

int findPoisonedDuration(int* timeSeries, int timeSeriesSize, int duration) {
    int count = 0;
    int i = 0;
    while (i < timeSeriesSize - 1)
    {
        if (timeSeries[i] + duration - 1 < timeSeries[i + 1])
        {
            count += duration;
        }
        else
        {
            count += timeSeries[i + 1] - timeSeries[i];
        }
        i++;
    }
    count += duration;
    return count;
}


int* nextGreaterElement(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize) {
    int* ans = (int*)malloc(sizeof(int) * nums1Size);
    *returnSize = nums1Size;
    int j = 0;
    for (int i = 0; i < nums1Size; i++)
    {
        int flag = 0;
        for (j = 0; j < nums2Size; j++)
        {
            if (nums2[j] == nums1[i])
            {
                break;
            }
        }
        for (j++; j < nums2Size; j++)
        {
            if (nums2[j] > nums1[i])
            {
                ans[i] = nums2[j];
                flag = 1;
                break;
            }
        }
        if (flag == 0)
        {
            ans[i] = -1;
        }
    }
    return ans;
}

int main()
{
    int arr1[] = { 4,1,2 };
    int arr2[] = { 1,3,4,2 };
    int sz1 = sizeof(arr1) / sizeof(arr1[0]);
    int sz2 = sizeof(arr2) / sizeof(arr2[0]);
    int i = 1;
    nextGreaterElement(arr1, sz1, arr2, sz2, &i);
    return 0;
}